package video.dali.common.utils;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.HashMap;

public class JwtUtil {


    //设置jwt
    public static  String createJwt(HashMap<String,Object> claims, String secretKey, long ttl){
        String jwt = Jwts.builder()
                .addClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis() + ttl))
                .signWith(SignatureAlgorithm.HS256, secretKey)
                .compact();
        return jwt;
    }

    //解析jwt
    public static void parseJwt(String jwt){
       Jwts.parser().setSigningKey("ihua").parseClaimsJws(jwt).getBody();
    }
}
